package command

import (
	"fmt"
	"github.com/spf13/cobra"
	"go-demo-2025/common"
	"log"
	"os"
)

// 定义全局变量参数
var (
	operate string //操作内容
)

var RootCmd = &cobra.Command{
	Use:   "111",
	Short: "-v",
	Long:  `111`,
	Run: func(cmd *cobra.Command, args []string) {
		usageStr := `欢迎，可以使用-h查看命令`
		log.Printf("%s\n", usageStr)
	},
}

func init() {
	//在init函数中添加全局flag
	RootCmd.PersistentFlags().StringVar(&operate, "operate", "", "set operate")

	// 初始化配置
	common.InitConfig()
}

func Execute() {
	if err := RootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
